﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://www.codeplex.com/EmlenMud
using System;
using System.Xml.Serialization;
using System.Runtime.Serialization;
using System.ComponentModel;

namespace BrainTechLLC
{
    [DataContract]
    public struct Int2x2
    {
        public static readonly long Div1024 = (1024) + (1024 << 31);
        [DataMember]
        public long xy1;
        [DataMember]
        public long xy2;

        public int X1, Y1, X2, Y2;

        public void SetXY(long v1, long v2)
        {
            xy1 = v1;
            xy2 = v2;
        }
        public void SetXY(int x1, int y1, int x2, int y2)
        {
            X1 = x1; Y1 = y1; X2 = x2; Y2 = y2;
            xy1 = x1 + (y1 << 31);
            xy2 = x2 + (y2 << 31);
        }
        public bool Eq() { return xy1 == xy2; }
        public Int2x2(int x1, int y1, int x2, int y2)
        {
            X1 = x1; Y1 = y1; X2 = x2; Y2 = y2;
            xy1 = x1 + (y1 << 31);
            xy2 = x2 + (y2 << 31);
        }

        public Int2x2(Int2x2 other)
        {
            xy1 = other.xy1;
            xy2 = other.xy2;
            X1 = other.X1;
            X2 = other.X2;
            Y1 = other.Y1;
            Y2 = other.Y2;
        }

        public Int2x2(Int2x2 other, bool div1024)
        {
            xy1 = other.xy1 / Div1024;
            xy2 = other.xy2 / Div1024;
            X1 = other.X1 / 1024;
            X2 = other.X2 / 1024;
            Y1 = other.Y1 / 1024;
            Y2 = other.Y2 / 1024;
        }
    }
}
